//
//  TWbHomeVC.m
//  TencentWB
//
//  Created by kong_jinbiao on 14-5-13.
//  Copyright (c) 2014年 user. All rights reserved.
//

#import "TWbHomeVC.h"
#import "WeiboApi.h"
#import "TWbStatusesManager.h"

@interface TWbHomeVC ()<WeiboAuthDelegate>
{
    NSMutableArray *m_weiboDataArr;
}

@property (nonatomic,strong)WeiboApi *weiboApi;
@property (nonatomic,strong)NSMutableArray *m_weiboDataArr;
@end

@implementation TWbHomeVC
@synthesize weiboApi;
@synthesize m_weiboDataArr;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
//    [super viewDidLoad];
    [self performSelector:@selector(oauthAction) withObject:nil afterDelay:0.1];
    self.title = @"Test";
}

#pragma mark---private
-(void)oauthAction
{
    //授权
    self.weiboApi = [[WeiboApi alloc]initWithAppKey:AppKey andSecret:AppSecret andRedirectUri:APPURL andAuthModeFlag:0 andCachePolicy:0];
    [weiboApi loginWithDelegate:self andRootController:self];
}

/**
 *  保存token信息
 */
-(void)setTokenInfo
{
    
}

#pragma  mark---WeiboAuthDelegate
/**
 * @brief   授权成功后的回调
 * @param   INPUT   wbapi 成功后返回的WeiboApi对象，accesstoken,openid,refreshtoken,expires 等授权信息都在此处返回
 * @return  无返回
 */
- (void)DidAuthFinished:(WeiboApiObject *)wbobj;
{
    NSLog(@"--->>Finished");
    [Utils setTokenInfo:wbobj];
    TWbStatusesManager *manager = [TWbStatusesManager shareInstance];
    [manager queryStatusesHomeTimelineWithPageFlag:@"0" pagetime:@"0" reqnum:@"70" type:@"3" contenttype:@"0" completeBlock:^(TWbHomeTimeLineOutput *outPut, NSError *error) {
        if(error)
        {
            
        }
        else
        {
            self.m_weiboDataArr = outPut.m_dataArr;
        }
    }];
}

- (void)DidAuthCanceled:(WeiboApiObject *)wbobj;
{
    NSLog(@"--->>Cancel");
}

/**
 * @brief   授权成功后的回调
 * @param   INPUT   error   标准出错信息
 * @return  无返回
 */
- (void)DidAuthFailWithError:(NSError *)error;
{
    NSLog(@"--->>Oauth Error");
}

/**
 * @brief   选择使用服务器验证token有效性（checkAuthValid）时，需实现此回调
 * @param   INPUT   bResult   检查结果，yes 为有效，no 为无效
 * @param   INPUT   strSuggestion 当bResult 为no 时，此参数为建议。
 * @return  无返回
 */
- (void)didCheckAuthValid:(BOOL)bResult suggest:(NSString*)strSuggestion;
{
    NSLog(@"--->>didCheckAuthValid");
}


- (IBAction)oAuthTest:(id)sender {
    [self oauthAction];
}
@end
